<?php

namespace App\Models;

use Illuminate\Database\Eloquent\SoftDeletes;

class Article extends Model
{
    use SoftDeletes;
    protected $dates = ['deleted_at'];
    protected $hidden = ['deleted_at'];

    protected $guarded = [];

    protected $casts = [
        'type' => 'integer',
        'other_infos' => 'array',
        'is_show' => 'boolean',
        'is_show_index' => 'boolean',
    ];

    public function scopeShowIndexFormat($query)
    {
        return $query->select('id', 'type', 'title', 'cover', 'views', 'fake_views', 'created_at')->selectRaw('left(body, ?) as body', [200]);
    }
}
